package org.example.interfaceisolation;

/**
 * @author
 * @description
 */
public class InterfaceIsolation2 {
    public static void main(String[] args) {
        //A1类通过接口依赖(使用)B1类
        A1 a1 = new A1();
        a1.depend1(new B1());
        a1.depend2(new B1());
        a1.depend3(new B1());

        //C1类通过接口依赖(使用)D1类
        C1 c1 = new C1();
        c1.depend1(new D1());
        c1.depend4(new D1());
        c1.depend5(new D1());

    }
}

//接口
interface Interface11 {
    void operation1();

}

interface Interface22 {

    void operation2();

    void operation3();
}

interface Interface33 {

    void operation4();

    void operation5();
}



class B1 implements Interface11, Interface22 {
    @Override
    public void operation1() {
        System.out.println("B1 实现了 operation1");
    }

    @Override
    public void operation2() {
        System.out.println("B1 实现了 operation2");
    }

    @Override
    public void operation3() {
        System.out.println("B1 实现了 operation3");
    }

}





class D1 implements Interface11, Interface33 {
    @Override
    public void operation1() {
        System.out.println("D1 实现了 operation1");
    }


    @Override
    public void operation4() {
        System.out.println("D1 实现了 operation4");
    }

    @Override
    public void operation5() {
        System.out.println("D1 实现了 operation5");
    }
}

class A1 { //A类通过接口Interface1依赖(使用)B类，但是只会用到1,2,3方法
    public void depend1(Interface11 i) {
        i.operation1();
    }

    public void depend2(Interface22 i) {
        i.operation2();
    }

    public void depend3(Interface22 i) {
        i.operation3();
    }
}

class C1{ //C类通过接口Interface1依赖(使用)D类，但是只会用到1,4,5方法
    public void depend1(Interface11 i) {
        i.operation1();
    }

    public void depend4(Interface33 i) {
        i.operation4();
    }

    public void depend5(Interface33 i) {
        i.operation5();
    }
}
